package com.ethan.cj.ssm.util;

import com.sun.istack.internal.NotNull;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.Setter;
import lombok.ToString;

import java.util.List;

/**
 * 分页工具
 *
 * @param <T> 实体类
 */

@Setter
@Getter
@ToString
@RequiredArgsConstructor
public class PageBean<T> {
    private final int pageIndex;      //当前页数
    private final int pageSize;        //单页信息数
    private int totalCount;     //数据总数
    private List<T> list;           //该页数据集合

    public int getTotalPage() {
        if (pageSize != 0) {
            return totalCount % pageSize == 0 ? totalCount / pageSize : totalCount / pageSize + 1;
        }
        return 0;
    }

    public int getOffset() {
        return (pageIndex - 1) * pageSize;
    }

}
